<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<title>e网批发管理后台</title>
	<?php 
	include("common/conn.php"); 
	include("./tool/UpFileTool.class.php");
	if($_SESSION['userid']==""){
		echo "<script>window.location.href='login.php';</script>";
		exit;
	} 

if($_GET['action']=="ok"){
	$title = !empty($_REQUEST['title'])?$_REQUEST['title']: '';
	$content = !empty($_REQUEST['content'])?$_REQUEST['content']: '';
	if ($_FILES[upfile][tmp_name]!='') {
		$UpFileTool=new UpFileTool('upfile');
		$UpFileTool->sumbImage($w=640, $h=360);
		$UpFileTool->upFile();
		$images = $UpFileTool->sumbImage;
		$srcimages = $UpFileTool->srcImage;
		
	}else{
		$images='';
	}
	$start2=mysql_query("INSERT INTO article(title,image,content) VALUES ('$title','$images','$content')");
	echo "<script>alert('新增快讯成功!');window.location.href='kuaixun.php';</script>";

}

if($_GET['ch']=="ok"){ 
	$title = !empty($_REQUEST['title'])?$_REQUEST['title']: '';
	$content = !empty($_REQUEST['content'])?$_REQUEST['content']: '';
	if ($_FILES[upfile][tmp_name]!='') {
		$UpFileTool=new UpFileTool('upfile');
		$UpFileTool->sumbImage($w=640, $h=360);
		$UpFileTool->upFile();
		$images = $UpFileTool->sumbImage;
		$srcimages = $UpFileTool->srcImage;
		$srat1=mysql_query("UPDATE article set title='".$title."',image='".$images."' where id=".$_REQUEST['id']);
	}
	if($title!=''){
		mysql_query("UPDATE article set title='".$title."' where id=".$_REQUEST['id']);
	}
	if($content!=''){
		mysql_query("UPDATE article set content='".$content."' where id=".$_REQUEST['id']);
	}
	echo "<script>alert('修改快讯信息成功!');window.location.href='kuaixun.php';</script>";
}
// 查找快讯信息
if($_REQUEST['editid']!=""){
	$query = mysql_query("select * from article where id='".$_GET['editid']."'");
	$ad = mysql_fetch_array($query);
}

?>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/style2.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="write/themes/default/default.css" />
	<script charset="utf-8" src="write/kindeditor-min.js"></script>
	<script charset="utf-8" src="write/lang/zh_CN.js"></script>
	<script>
		var editor;
		KindEditor.ready(function(K) {
			editor = K.create('textarea[name="content"]', {
				allowFileManager : true
			});
			K('input[name=getHtml]').click(function(e) {
				alert(editor.html());
			});
			K('input[name=isEmpty]').click(function(e) {
				alert(editor.isEmpty());
			});
			K('input[name=getText]').click(function(e) {
				alert(editor.text());
			});
			K('input[name=selectedHtml]').click(function(e) {
				alert(editor.selectedHtml());
			});
			K('input[name=setHtml]').click(function(e) {
				editor.html('<h3>Hello KindEditor</h3>');
			});
			K('input[name=setText]').click(function(e) {
				editor.text('<h3>Hello KindEditor</h3>');
			});
			K('input[name=insertHtml]').click(function(e) {
				editor.insertHtml('<strong>插入HTML</strong>');
			});
			K('input[name=appendHtml]').click(function(e) {
				editor.appendHtml('<strong>添加HTML</strong>');
			});
			K('input[name=clear]').click(function(e) {
				editor.html('');
			});
		});


	</script>
</head>

<body>

	<!--header-->
	<?php include("common/header.php");?>
	<!--header end-->


	<!-- staqrt subnav -->
	<div id="sub_nav">
	</div>
	<div class="container_12" style=" border-bottom:100px;">
		<form action="?<?php if($_GET['editid']!=""){echo "ch=ok"; ?>&id=<?php echo $_GET['editid'];}else{echo "action=ok";}?>" method="post" enctype="multipart/form-data"  >
			<!--主图-->
			<div class="car_mode" >

				<div class="indexfloat" style="width:75%; margin-left:5%;">
					<label>快讯主图</label>
					<span style="font-size: 12px;">(为了保持APP版面的协调性，请上传16:9的图片)</span>
				</div> 

				<div class="indexfloat" style="width:79%;" >
					<input name="upfile" type="file" /><img src="<?php echo $ad[image];?>"  height="auto" width="250"/>
				</div>

			</div>
			<!-- 主图 end -->

			<!-- 快讯标题 -->
			<div class="car_mode" >

				<div class="indexfloat" style="width:75%; margin-left:5%;">
					<label>快讯名称</label>
				</div> 

				<div class="indexfloat" style="width:79%;" >
					<input name="title" type="text" value="<?php echo $ad[title];?>"/>
				</div>

			</div>
			<!-- 快讯标题 end -->

			
			<div class="car_mode contentType" >
				<div class="indexfloat" style="width:15%; margin-left:5%;">
					<label>快讯详情</label>
				</div>

				<div class="indexfloat" style="width:79%;" >
					<textarea name="content" style="height:500px;">
						<?php 
						if ($ad[content]) {
							echo $ad[content];
						}else{
							echo "";
						}
						?>
					</textarea>
				</div>

			</div>
			<!-- 快讯详情 end -->

		<!--收货信息-->
		<div class="car_mode" style="margin-bottom:100px;" >
<!-- 			<input name="shopid" type="hidden" value="<?php echo $_REQUEST[shopid];?>" /> -->
			<input name="" type="submit" class="submit"  value="提交" />
		</div>

		<!--收货信息 end-->



	</form>          
</div>

<!-- end content wrap -->

</form>
</body>
</html>

<script type="text/javascript">
	function zi(n)
	{
		for(var i=1;i<=50;i++)
		{
			document.getElementById(i).style.display="none"; 
			document.getElementById(n).style.display="block";  
		}

	}

	function zis(n)
	{
		for(var i=100;i<=150;i++)
		{
			document.getElementById(i).style.display="none"; 
			document.getElementById(n).style.display="block";  
		}

	}
	// 选择不同的快讯类型
	$('input[name="type"]').change(function(){
		var type = $(this).val();
		if (type == 0) {
			$('.contentType').css('opacity','1');
			$('.contentType').css('height','auto');
			$('.categroyType').hide();
			$('.shopType').hide();
		}else if (type == 1) {
			$('.contentType').css('opacity','0');
			$('.contentType').css('height','0');
			$('.categroyType').show();
			$('.shopType').hide();
		}else if (type == 2) {
			$('.contentType').css('opacity','0');
			$('.contentType').css('height','0');
			$('.categroyType').hide();
			$('.shopType').show();
		};
	})
	// 选择不同的快讯类型 end
</script>